package compSci.project.database.GUI;

import javax.swing.JPanel;
import java.awt.BorderLayout;

import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.JSplitPane;
import javax.swing.JEditorPane;
import javax.swing.JList;
import javax.swing.ListSelectionModel;

import compSci.project.database.main.DB;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.JTabbedPane;

public class ADD extends JPanel{

	/**
	 * Create the panel.
	 */
	
	public ADD() {
		setLayout(new BorderLayout(0, 0));
		
		JSplitPane splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.05);
		splitPane.setContinuousLayout(true);
		add(splitPane, BorderLayout.CENTER);
		
		JScrollPane scrollPane = new JScrollPane();
		splitPane.setLeftComponent(scrollPane);
		
		/*DefaultListModel<String> listModel = new DefaultListModel<String>();
		
		for(String item: DB.list){
			listModel.addElement(item);
		}
		*/
		final JList list = new JList(DB.list.toArray());
		
		
		ListSelectionListener listSelectionListener = new ListSelectionListener() {
		      public void valueChanged(ListSelectionEvent e) {
		       
		        if (!e.getValueIsAdjusting()) {
		        	String a = list.getSelectedValue().toString();
		        	//System.out.println(a);
		        	JOptionPane.showMessageDialog(null, a, "test", JOptionPane.ERROR_MESSAGE);
		        }
		      }
		    };
		list.addListSelectionListener(listSelectionListener);
		scrollPane.setViewportView(list);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		splitPane.setRightComponent(tabbedPane);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("New tab", null, panel, null);
		
	}

}
